package com.jiepu.daily.corejava.advanceed.part2.day0725;

import java.lang.reflect.Field;

/**
 * @Description:
 * @author: xinjie.txt
 * @date: 2020/7/25  10:35
 */
public class ReflectionDemo1 {
	public static void main(String[] args)
			throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {

		Student student = new Student("xinjie.txt");




		// 获取镜像的 三种办法  包名路径；类名.class； 对象.getClass()

		// 1. Class.forName()  参数 -- 全限类名
		// 可实现 配置文件 传参    解耦
		Class cls1 = Class.forName("com.jiepu.daily.corejava.advanceed.part2.day0725.Student");
		System.out.println(cls1);

		//2. 类名.class
		// 实现最简单
		Class cls2 = Student.class;
		System.out.println(cls2);

		//3. 对象.getClass()
		// 需要依赖对象
		Class cls3 = student.getClass();
		System.out.println(cls3);

		System.out.println(cls1==cls2); // true
		System.out.println(cls2==cls3); // true

		//
		Field nameField = cls1.getDeclaredField("name");
		Field schoolName = cls1.getDeclaredField("SCHOOL_NAME");
		// 暴力破解  设置name属性可见性。
		nameField.setAccessible(true);

		System.out.println(nameField.get(student));
		System.out.println(schoolName.get(student));
	}
}
